package com.turbo.cloud.ums.web.webservice;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.turbo.cloud.core.api.R;
import com.turbo.cloud.core.api.Result;
import com.turbo.cloud.core.base.PageQuery;
import com.turbo.cloud.core.validated.InsertValidated;
import com.turbo.cloud.core.validated.UpdateValidated;
import com.turbo.cloud.ums.web.logic.PermissionLogic;
import com.turbo.cloud.ums.web.model.permission.*;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 权限表 前端控制器
 * </p>
 *
 * @author zhangluning
 * @since 2022-10-11
 */
@RequiredArgsConstructor
@RestController
public class UmsPermissionController {

    final PermissionLogic permissionLogic;

    /**
     * 查询权限分页列表
     *
     * @param pageQuery 分页查询条件
     * @return Page
     */
    @PostMapping(name = "查询权限分页列表", value = "/webservice/permission/queryPermissionPage")
    public Result<Page<UmsPermissionVo>> queryPermissionPage(@RequestBody PageQuery<UmsPermissionQo> pageQuery) {
        Page<UmsPermissionVo> result = permissionLogic.queryPermissionPage(pageQuery);
        return R.result(result);
    }

    /**
     * 查询权限分页列表，并根据角色ID标记选中
     *
     * @param pageQuery 分页查询条件
     * @return
     */
    @PostMapping(name = "查询权限分页列表，并根据角色ID标记选中", value = "/webservice/permission/queryPermissionCheckedPageOfRoleId")
    public Result<Page<UmsPermissionVo>> queryPermissionCheckedPageOfRoleId(@RequestBody PageQuery<UmsPermissionQo> pageQuery) {
        Page<UmsPermissionVo> result = permissionLogic.queryPermissionCheckedPageOfRoleId(pageQuery);
        return R.result(result);
    }

    /**
     * 查询权限列表，并根据角色ID标记选中
     *
     * @param roleId 角色Id
     * @return
     */
    @GetMapping(name = "查询权限列表，并根据角色ID标记选中", value = "/webservice/permission/queryPermissionCheckedListOfRoleId")
    public Result<List<UmsPermissionVo>> queryPermissionCheckedListOfRoleId(String roleId) {
        List<UmsPermissionVo> result = permissionLogic.queryPermissionCheckedListOfRoleId(roleId);
        return R.result(result);
    }

    /**
     * 新增权限
     *
     * @param umsPermissionDo 实体
     * @return
     */
    @PostMapping(name = "新增权限", value = "/webservice/permission/createPermission")
    public Result<Boolean> createPermission(@RequestBody @Validated(InsertValidated.class) UmsPermissionDo umsPermissionDo) {
        boolean result = permissionLogic.createPermission(umsPermissionDo);
        return R.result(result);
    }

    /**
     * 修改权限
     *
     * @param umsPermissionDo 实体
     * @return
     */
    @PostMapping(name = "修改权限", value = "/webservice/permission/modifyPermission")
    public Result<Boolean> modifyPermission(@RequestBody @Validated(UpdateValidated.class) UmsPermissionDo umsPermissionDo) {
        boolean result = permissionLogic.modifyPermission(umsPermissionDo);
        return R.result(result);
    }

    /**
     * 开启、关闭权限有效状态
     *
     * @param id 权限ID
     * @return Boolean
     */
    @GetMapping(name = "开启、关闭权限有效状态", value = "/webservice/permission/enabledPermissionStateById")
    public Result<Boolean> enabledPermissionStateById(@RequestParam @NotBlank(message = "权限ID不能为空") String id) {
        boolean result = permissionLogic.enabledPermissionStateById(id);
        return R.result(result);
    }

    /**
     * 删除权限
     *
     * @param id 权限ID
     * @return
     */
    @GetMapping(name = "删除权限", value = "/webservice/permission/removePermissionById")
    public Result<Boolean> removeRoleById(@RequestParam @NotBlank(message = "权限ID不能为空") String id) {
        boolean result = permissionLogic.removePermissionById(id);
        return R.result(result);
    }

    /**
     * 绑定权限和菜单关系
     *
     * @param umsPermissionMenuRelationDo 实体
     * @return
     */
    @PostMapping(name = "绑定权限和菜单关系", value = "/webservice/permission/bindPermissionMenuRelation")
    public Result<Boolean> bindPermissionMenuRelation(@RequestBody @Validated(InsertValidated.class) UmsPermissionMenuRelationDo umsPermissionMenuRelationDo) {
        boolean result = permissionLogic.bindPermissionMenuRelation(umsPermissionMenuRelationDo);
        return R.result(result);
    }

    /**
     * 解除绑定权限和菜单关系
     *
     * @param umsPermissionMenuRelationDo 实体
     * @return
     */
    @PostMapping(name = "解除绑定权限和菜单关系", value = "/webservice/permission/unBindPermissionMenuRelation")
    public Result<Boolean> unBindPermissionMenuRelation(@RequestBody @Validated(InsertValidated.class) UmsPermissionMenuRelationDo umsPermissionMenuRelationDo) {
        boolean result = permissionLogic.unBindPermissionMenuRelation(umsPermissionMenuRelationDo);
        return R.result(result);
    }

    /**
     * 绑定权限和组件关系
     *
     * @param umsPermissionComponentRelationDo 实体
     * @return
     */
    @PostMapping(name = "绑定权限和组件关系", value = "/webservice/permission/bindPermissionComponentRelation")
    public Result<Boolean> bindPermissionComponentRelation(@RequestBody @Validated(InsertValidated.class) UmsPermissionComponentRelationDo umsPermissionComponentRelationDo) {
        boolean result = permissionLogic.bindPermissionComponentRelation(umsPermissionComponentRelationDo);
        return R.result(result);
    }

    /**
     * 解除绑定权限和组件关系
     *
     * @param umsPermissionComponentRelationDo 实体
     * @return
     */
    @PostMapping(name = "解除绑定权限和组件关系", value = "/webservice/permission/unBindPermissionComponentRelation")
    public Result<Boolean> unBindPermissionComponentRelation(@RequestBody @Validated(InsertValidated.class) UmsPermissionComponentRelationDo umsPermissionComponentRelationDo) {
        boolean result = permissionLogic.unBindPermissionComponentRelation(umsPermissionComponentRelationDo);
        return R.result(result);
    }

    /**
     * 绑定权限和接口关系
     *
     * @param umsPermissionApiRelationDo 实体
     * @return
     */
    @PostMapping(name = "绑定权限和接口关系", value = "/webservice/permission/bindPermissionApiRelation")
    public Result<Boolean> bindPermissionApiRelation(@RequestBody @Validated(InsertValidated.class) UmsPermissionApiRelationDo umsPermissionApiRelationDo) {
        boolean result = permissionLogic.bindPermissionApiRelation(umsPermissionApiRelationDo);
        return R.result(result);
    }

    /**
     * 解除绑定权限和接口关系
     *
     * @param umsPermissionApiRelationDo 实体
     * @return
     */
    @PostMapping(name = "解除绑定权限和接口关系", value = "/webservice/permission/unBindPermissionApiRelation")
    public Result<Boolean> unBindPermissionApiRelation(@RequestBody @Validated(InsertValidated.class) UmsPermissionApiRelationDo umsPermissionApiRelationDo) {
        boolean result = permissionLogic.unBindPermissionApiRelation(umsPermissionApiRelationDo);
        return R.result(result);
    }
}
